<!doctype html>
<html class="x-admin-sm" lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台登录</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" th:href="@{/admin/css/font.css}">
    <link rel="stylesheet" th:href="@{/admin/css/login.css}">
    <link rel="stylesheet" th:href="@{/admin/css/xadmin.css}">
    <script type="text/javascript" th:src="@{/admin/js/jquery-3.5.1.min.js}"></script>
    <script type="text/javascript" th:src="@{/admin/lib/layui/layui.js}"></script>
    <script type="text/javascript" th:src="@{/admin/js/global.js}"></script>
</head>
<body class="login-bg">

<div class="login layui-anim layui-anim-account">
    <div class="message">农资商城销售系统</div>
    <div id="darkbannerwrap"></div>
    <input name="phone" id="phone" placeholder="手机号" type="text" lay-verify="required" class="layui-input">
    <hr class="hr15">
    <input name="password" id="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
    <hr class="hr15">
    <input value="登录" id="btn" class="layui-btn" style="width: 340px;height: 50px;font-size: 28px;">
    <hr class="hr20">
</div>
<script>

    layui.use('form', function () {
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;

        $("#btn").on("click", function () {
            let phone = $("#phone").val();
            let password = $("#password").val();
            //验证phone是否是手机号格式
            if(!(/^1[3456789]\d{9}$/.test(phone))){
                layer.msg('手机号格式不正确', {
                    icon: 5,
                    time: 2000
                });
                return;
            }
            if (!phone ||!password) {
                layer.msg('手机号和密码不能为空', {
                    icon: 5,
                    time: 2000
                });
                return;
            }
            $.post(prefix + '/admininfo/login', {phone, password}, function (res) {
                if (res.code === 200) {
                    setUserName(res.msg);
                    layer.msg("登录成功", {
                        icon: 1,
                        time: 2000
                    }, function () {
                        window.location.href = "/admin/index";
                    });
                } else {
                    layer.msg(res.msg, {
                        icon: 5,
                        time: 2000
                    });
                }
            }, "json");
        })
    });

</script>
<!-- 底部结束 -->
</body>
</html>
